let uu = document.querySelector("#uu");
let menu_div = document.querySelector("#menu>div");
let discounts = document.querySelector("#Discounts");
//渲染菜单栏
function menu() {
    let res;
    ajax({
        url: "http://chst.vip:1234/api/getindexmenu",
        success(res) {
            res = res.result;
            let currentArr = res.splice(0, 12);
            let html = "";
            currentArr.forEach(itme => {
                // console.log(itme);
                if (itme.titlehref === "moneyctrl.html") {
                    itme.titlehref = "moneyctrl.html?pageid=0"
                }
                html += `
                <li><a href="${itme.titlehref}">${itme.img}</a>
                <p>${itme.name}</p></li>`
                uu.innerHTML = html
            });
            let lis = uu.children;
            let li = [...lis];
            let i = 0;
            li[7].onclick = function() {
                i++
                if (i % 2 === 0) {
                    menu_div.style.height = 5.6 + "rem"
                } else {
                    menu_div.style.height = 8.5 + "rem"
                }
            }
            let a = `<a href="${currentArr[1].titlehref}">更多优惠>></a>`
            discounts.innerHTML = a
        },
        error(err, xhr) {
            console.log(err);
        }
    })
}
menu();
// 渲染商品栏
function recommen() {
    let res
    let uu1 = document.querySelector("#uu1")
    ajax({
        url: " http://chst.vip:1234/api/getmoneyctrl",
        success(res) {
            res = res.result;
            let html = "";
            let currentArr = res.splice(0, 10);
            currentArr.forEach(itme => {
                html += `
                <li productid=${itme.productId}>
                <a href="#">
                ${itme.productImgSm}
                </a>
               <div>
               <a href="#">
               <p>${itme.productName}</p>
           </a>
           <a href="#">
               <p>${itme.productFrom}${itme.productTime}</p>
           </a></div>
            </li>`
            });
            uu1.innerHTML = html;
            [...uu1.children].forEach(li => {
                li.onclick = function() {
                    let productid = this.getAttribute('productid')
                    console.log(productid);
                    location.href = `/src/pages/moneyproduct.html?productid=${productid}`
                }
            })
        }
    })
}
recommen();
// 回到顶部
let backTop = document.querySelector("#backTop");
backTop.onclick = function() {
    document.getElementById('menu').scrollTop = 0
}
document.getElementById('menu').onscroll = function() {}